package com.nova.bluetooth.ui.device;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.fragment.app.Fragment;

import com.nova.bluetooth.R;
import com.nova.bluetooth.base.BaseActivity;
import com.nova.bluetooth.databinding.ActivityDeviceContainerBinding;

public class DeviceContainerActivity extends BaseActivity {
    public static void startThisActivity(Activity activity, int fragmentTag) {
        Intent intent = new Intent(activity, DeviceContainerActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt(FRAGMENT_TAG, fragmentTag);
        intent.putExtras(bundle);
        activity.startActivity(intent);
    }

    public final static int FRAGMENT_TAG_FIND_DEVICE = 0;
    public final static int FRAGMENT_TAG_EQ_SETTING = 1;
    public final static int FRAGMENT_TAG_KEY_FUNCTION = 2;


    private ActivityDeviceContainerBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        binding = ActivityDeviceContainerBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        loadFragment();
    }

    private final static String FRAGMENT_TAG = "fragment_tag";

    private void loadFragment() {
        Fragment mFragment = null;
        int fragment_tag = getIntent().getIntExtra(FRAGMENT_TAG, 0);
        switch (fragment_tag) {
            case FRAGMENT_TAG_FIND_DEVICE:
                mFragment = new FindDeviceFragment();
                break;
            case FRAGMENT_TAG_EQ_SETTING:
                mFragment = new EQSettingFragment();
                break;
            case FRAGMENT_TAG_KEY_FUNCTION:
                mFragment = new KeyFunctionFragment();
                break;
        }

        // 加载默认的Fragment
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.fragment_container, mFragment)
                .commit();
    }
}